﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

namespace Galaxy.AutoCAD.Databases
{
    public static class LineTool
    {
        #region 创建直线（定义为database的扩展函数）
        public static ObjectId CreateLine(this Database db, Point3d startPt, Point3d endPt)
        {
            Line line = new Line(startPt, endPt);
            ObjectId result = ObjectId.Null;
            using (Transaction tran = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                result = btr.AppendEntity(line);
                tran.AddNewlyCreatedDBObject(line, true);
                tran.Commit();
            }
            return result;
        }
        #endregion
    }
}
